package com.itheima.itheima_health.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.itheima_health.constant.MessageConstant;
import com.itheima.itheima_health.entity.PageResult;
import com.itheima.itheima_health.entity.QueryPageBean;
import com.itheima.itheima_health.exception.BaseException;
import com.itheima.itheima_health.mapper.BookingMapper;
import com.itheima.itheima_health.pojo.CheckItem;
import com.itheima.itheima_health.service.CheckitemTermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckitemTermServiceImpl implements CheckitemTermService {

    @Autowired
    private BookingMapper bookingMapper;
    @Override
    public void CheckitemTermAdd(CheckItem checkItem) {
        bookingMapper.CheckitemTermAdd(checkItem);
    }

    @Override
    public PageResult CheckitemTerPageQuery(QueryPageBean queryPageBean) {
        //开始分页
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<CheckItem> page = bookingMapper.CheckitemTerPageQuery(queryPageBean);

        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void CheckitemTermDelete(Long id) {
        //先判断检查项是否绑定了检查组
        Integer count = bookingMapper.findCountByCheckitem(id);
        if (count>0){
            throw new BaseException(MessageConstant.DELETE_CHECKITEM_FAIL1);
        }
        //根据id删除检查项
        bookingMapper.CheckitemTermDelete(id);
    }

    @Override
    public CheckItem CheckitemTergetByid(Long id) {
        //根据id回显检查项数据
        CheckItem checkItem = bookingMapper.CheckitemTergetByid(id);
        return checkItem;
    }

    @Override
    public void CheckitemTerUpdate(CheckItem checkItem) {
        //修改检查项数据
        bookingMapper.CheckitemTergetUpdate(checkItem);
    }

    @Override
    public List<CheckItem> getallCheckitem() {
        List<CheckItem> checkItemList = bookingMapper.getallCheckitem();
        return checkItemList;
    }
}
